package com.test.restresources;

import java.io.IOException;
import java.io.InputStream;
import java.nio.file.Files;
import java.nio.file.Paths;
import java.util.List;

import javax.ws.rs.Consumes;
import javax.ws.rs.GET;
import javax.ws.rs.POST;
import javax.ws.rs.Path;
import javax.ws.rs.Produces;
import javax.ws.rs.QueryParam;
import javax.ws.rs.core.MediaType;

import org.apache.cxf.jaxrs.ext.multipart.Attachment;
import org.apache.cxf.jaxrs.ext.multipart.Multipart;
import org.apache.cxf.jaxrs.ext.multipart.MultipartBody;

@Path("/rest")
@Produces({ "text/html" })
public class Resource1 {

	private String name;

	@Path("/name")
	@GET
	public String getName() {
		return name;
	}

	@Path("/name/{param}")
	@GET
	public void setName(@QueryParam("param") String name) {
		this.name = name;
	}

	public Resource1(String name) {
		this.name = name;
	}

	public Resource1() {
		this.name = "Rachit";
	}

	@POST
	@Path("/upload")
	@Produces(MediaType.TEXT_HTML)
	@Consumes(MediaType.MULTIPART_FORM_DATA)
	public String uploadFile(@Multipart("multipart_text") String text, @Multipart("multipart_file") Attachment attachment) throws IOException {
		String filename = attachment.getContentDisposition().getParameter("filename");
		return "uploaded " + text + "and " + filename;
	}

}
